package com.zg.autoflow.web;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zg.autoflow.req.SettleWorkflowReq;
import com.zg.autoflow.service.SettleWorkflowService;
import com.zg.autoflow.vo.SettleWorkflowVo;
import com.zg.common.core.R;
import com.zg.common.core.dao.autoflow.entity.SettleWorkflow;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = {"流程配置"})
@RestController
@RequiredArgsConstructor
public class SettleWorkflowController {

    private final SettleWorkflowService settleWorkflowService;

    /**
     * 查询可发起的流程
     * @param settleWorkflowReq
     * @return
     */
    @ApiOperation("查询可发起的流程")
    @PostMapping("/flow/settleWorkflow/getCanRunWorkflowPage")
    public R<IPage<SettleWorkflowVo>> page(@RequestBody SettleWorkflowReq settleWorkflowReq) {
        Page<SettleWorkflow> pageInfo = settleWorkflowService.page(settleWorkflowReq);
        Page<SettleWorkflowVo> settleWorkflowVoPage = new Page<>();
        BeanUtil.copyProperties(pageInfo, settleWorkflowVoPage);
        return R.success(settleWorkflowVoPage);
    }

}
